package com.itheima03;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Test03 {
    static TreeMap<String,Integer> hm = new TreeMap<>();
    public static void main(String[] args) {
        File f1 = new File("E:\\");
        getConut(f1);
        Set<Map.Entry<String, Integer>> entry1 = hm.entrySet();
        for (Map.Entry<String, Integer> en : entry1) {
            String key = en.getKey();
            int value = en.getValue();
            System.out.println(key+"---"+value);
        }


    }

    public static void getConut(File f1) {
        File[] files = f1.listFiles();
        if (files == null){
            return;
        }
        //Set<String> name = hm.keySet();
        for (File file : files) {
            if(file.isFile()){
                String[] split = file.getName().split("\\.");
                if (split.length==2) {
                    String name = split[1];
                    if (hm.containsKey(name)) {
                        hm.put(name, hm.get(name) + 1);
                    } else {
                        hm.put(name, 1);
                    }
                }
            }else{
                getConut(file);
            }
        }
    }
}
